package com.cj.service.impl;

import com.cj.mapper.ArticleMapper;
import com.cj.mapper.CommentMapper;
import com.cj.service.StatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Service
public class StatsServiceImpl implements StatsService {
    @Autowired
    private ArticleMapper articleMapper;
    
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public Map<String, Object> getArticleViewStats(LocalDateTime startTime, LocalDateTime endTime) {
        Map<String, Object> result = new HashMap<>();
        result.put("totalViews", articleMapper.countTotalViews());
        result.put("periodViews", articleMapper.countViewsBetween(startTime, endTime));
        result.put("topArticles", articleMapper.getTopViewedArticles(5));
        return result;
    }

    @Override
    public Map<String, Object> getCommentLikeStats(LocalDateTime startTime, LocalDateTime endTime) {
        Map<String, Object> result = new HashMap<>();
        result.put("totalLikes", commentMapper.countTotalLikes());
        result.put("periodLikes", commentMapper.countLikesBetween(startTime, endTime));
        result.put("topComments", commentMapper.getTopLikedComments(5));
        return result;
    }
}
